package com.su.song.shapapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.Switch;
import android.widget.TextView;

public class ShapActivity extends AppCompatActivity implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {


    private View v_content;
    private TextView tv_swresult;
    private TextView cks_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shap);
        v_content = findViewById(R.id.v_content);
        findViewById(R.id.btn_angel).setOnClickListener(this);
        findViewById(R.id.btn_oval).setOnClickListener(this);

        CheckBox ck_system = findViewById(R.id.ck_system);
        CheckBox ck_custom = findViewById(R.id.ck_custom);
        ck_system.setOnCheckedChangeListener(this);
        ck_custom.setOnCheckedChangeListener(this);

        Switch sw_system = findViewById(R.id.sw_system);
        tv_swresult = findViewById(R.id.tv_swresult);
        sw_system.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                String desc = String.format("您%sl这个CheckBox",isChecked? "滑动":"取消了滑动");
                tv_swresult.setText(desc);
            }
        });

        CheckBox ck_switch = findViewById(R.id.ck_switch);
        cks_result = findViewById(R.id.cks_result);
        ck_switch.setOnCheckedChangeListener((buttonView, isChecked) -> {
            String desc = String.format("您%s了这个自定义控件",isChecked? "滑动":"取消了滑动");
            cks_result.setText(desc);
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_angel:
                v_content.setBackgroundResource(R.drawable.angle);
                break;
            case R.id.btn_oval:
                v_content.setBackgroundResource(R.drawable.oval);
                break;

        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        String desc = String.format("您%sl这个CheckBox",isChecked? "勾选":"取消了勾选");
        buttonView.setText(desc);
    }
}